package com.ruoyi.web.controller.students;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.student.domain.StudentsDorms;
import com.ruoyi.student.service.IStudentsDormsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 寝室信息Controller
 *
 *
 * @date 2024-04-16
 */
@RestController
@RequestMapping("/students/dorms")
public class StudentsDormsController extends BaseController
{
    @Autowired
    private IStudentsDormsService studentsDormsService;

    /**
     * 查询寝室信息列表
     */
    @PreAuthorize("@ss.hasPermi('students:dorms:list')")
    @GetMapping("/list")
    public TableDataInfo list(StudentsDorms studentsDorms)
    {
        startPage();
        List<StudentsDorms> list = studentsDormsService.selectStudentsDormsList(studentsDorms);
        return getDataTable(list);
    }

    /**
     * 导出寝室信息列表
     */
    @PreAuthorize("@ss.hasPermi('students:dorms:export')")
    @Log(title = "寝室信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StudentsDorms studentsDorms)
    {
        List<StudentsDorms> list = studentsDormsService.selectStudentsDormsList(studentsDorms);
        ExcelUtil<StudentsDorms> util = new ExcelUtil<StudentsDorms>(StudentsDorms.class);
        util.exportExcel(response, list, "寝室信息数据");
    }

    /**
     * 获取寝室信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('students:dorms:query')")
    @GetMapping(value = "/{dormsId}")
    public AjaxResult getInfo(@PathVariable("dormsId") String dormsId)
    {
        return success(studentsDormsService.selectStudentsDormsByDormsId(dormsId));
    }

    /**
     * 新增寝室信息
     */
    @PreAuthorize("@ss.hasPermi('students:dorms:add')")
    @Log(title = "寝室信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StudentsDorms studentsDorms)
    {
        return toAjax(studentsDormsService.insertStudentsDorms(studentsDorms));
    }

    /**
     * 修改寝室信息
     */
    @PreAuthorize("@ss.hasPermi('students:dorms:edit')")
    @Log(title = "寝室信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StudentsDorms studentsDorms)
    {
        return toAjax(studentsDormsService.updateStudentsDorms(studentsDorms));
    }

    /**
     * 删除寝室信息
     */
    @PreAuthorize("@ss.hasPermi('students:dorms:remove')")
    @Log(title = "寝室信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{dormsIds}")
    public AjaxResult remove(@PathVariable String[] dormsIds)
    {
        return toAjax(studentsDormsService.deleteStudentsDormsByDormsIds(dormsIds));
    }
}
